package org.spring.springboot.config.redlock;

import javax.annotation.PostConstruct;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 
 * 获取RedissonClient连接类
 */
@Component
public class RedissonConnector {
	 RedissonClient redisson;
	    @Value("${spring.redis.host}")
	    String host;
	    @Value("${spring.redis.port}")
	    String port;
	    @Value("${spring.redis.password}")
	    String password;
	    @Value("${spring.redis.timeout}")
	    String timeout;
	    @PostConstruct
	    public void init(){
	    	System.out.println("redisson连接触发");
	    	Config config = new Config();
	    	System.out.println("redis地址"+host);
	    	System.out.println("rediss端口"+port);
	    	config.useSingleServer().setAddress("redis://"+host+":"+port);
	    	config.useSingleServer().setPassword(password);
	    	config.useSingleServer().setDatabase(4);
	    	config.useSingleServer().setTimeout(Integer.valueOf(timeout));
	        redisson = Redisson.create(config);
	    }
    public RedissonClient getClient(){
        return redisson;
    }

}
